package com.lemon.exam.controller;

import com.lemon.exam.common.annotation.Web;
import com.lemon.exam.common.crud.BaseController;
import com.lemon.exam.entity.dto.RoleMenuResourceDTO;
import com.lemon.exam.entity.po.RolePO;
import com.lemon.exam.entity.vo.MenuResourceVO;
import com.lemon.exam.entity.vo.UserVO;
import com.lemon.exam.service.IRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 角色表 控制器
 *
 * @author Lemon
 * @since 2025/04/04 14:23:22
 */
@RestController
@RequestMapping("role")
@Tag(name = "角色管理", description = "角色表 API")
@Web(childUri = "role", childComponent = "system/Role.vue")
public class RoleController extends BaseController<RolePO, Long, IRoleService> {
    /**
     * 根据角色查询用户信息
     *
     * @param roleId
     * @return
     */
    @GetMapping("findUser/{roleId}")
    @Operation(summary = "查询当前角色的用户信息")
    public Flux<UserVO> findUser(@PathVariable("roleId") Long roleId) {
        return service.findUser(roleId);
    }

    /**
     * 根据角色查询菜单资源
     *
     * @param roleId
     * @return
     */
    @GetMapping("findMenuResource/{roleId}")
    @Operation(summary = "查询当前角色的菜单资源信息")
    public Flux<MenuResourceVO> findMenuResource(@PathVariable("roleId") Long roleId) {
        return service.findMenuResource(roleId);
    }

    /**
     * 更新
     *
     * @param param
     * @return
     */
    @PutMapping("updateMenuResource")
    @Operation(summary = "更新菜单权限")
    public Mono<String> updateMenuResource(@RequestBody List<RoleMenuResourceDTO> param) {
        return service.updateMenuResource(param);
    }
}
